home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue40 / Alfresco / TestUnit.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-31  |  2.1 KB  |  85 lines

  1. unit TestUnit;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls,
  8.   AAByteQ;
  9.  
  10. type
  11.   TForm1 = class(TForm)
  12.     Button1: TButton;
  13.     ListBox1: TListBox;
  14.     procedure Button1Click(Sender: TObject);
  15.   private
  16.     { Private declarations }
  17.   public
  18.     { Public declarations }
  19.   end;
  20.  
  21. var
  22.   Form1: TForm1;
  23.  
  24. implementation
  25.  
  26. {$R *.DFM}
  27.  
  28. const
  29.   TestOpCount = 20;
  30.   TestOps : array [1..TestOpCount] of integer =
  31.             ( 45,  12,  28, -45,  59, -12, -28,   5,  61,  11,
  32.               23, -59,  37,  -5, -61, -11, -23,  15, -37, -15);
  33.   TestData : string[TestOpCount] =
  34.               'ABCADBCEFGHDIEFGHJIJ';
  35.  
  36. procedure CreateBuffer(aCount : integer; aChar : char; aBuf : pointer);
  37. begin
  38.   FillChar(aBuf^, aCount, aChar);
  39. end;
  40.  
  41. procedure CheckBuffer(aCount : integer; aChar : char; aBuf : pointer);
  42. var
  43.   i : integer;
  44. begin
  45.   for i := 0 to pred(aCount) do
  46.     if (PChar(aBuf)[i] <> aChar) then
  47.       raise Exception.Create('Bad character');
  48. end;
  49.  
  50. procedure TForm1.Button1Click(Sender: TObject);
  51. var
  52.   MyByteQ : TaaByteQueue;
  53.   Buffer  : pointer;
  54.   i       : integer;
  55. begin
  56.   MyByteQ := TaaByteQueue.Create;
  57.   try
  58.     GetMem(Buffer, 64);
  59.     try
  60.       for i := 1 to TestOpCount do begin
  61.         if (TestOps[i] > 0) then begin
  62.           CreateBuffer(TestOps[i], TestData[i], Buffer);
  63.           MyByteQ.Put(Buffer^, TestOps[i]);
  64.           ListBox1.Items.Add(Format('Put %d %s''s  Count=%d Cap=%d',
  65.                                     [TestOps[i], TestData[i],
  66.                                      MyByteQ.Count, MyByteQ.Capacity]));
  67.         end
  68.         else begin
  69.           MyByteQ.Get(Buffer^, -TestOps[i]);
  70.           ListBox1.Items.Add(Format('Get %d %s''s  Count=%d Cap=%d',
  71.                                     [-TestOps[i], TestData[i],
  72.                                      MyByteQ.Count, MyByteQ.Capacity]));
  73.           CheckBuffer(-TestOps[i], TestData[i], Buffer);
  74.         end;
  75.       end;
  76.     finally
  77.       FreeMem(Buffer, 64);
  78.     end;
  79.   finally
  80.     MyByteQ.Free;
  81.   end;
  82. end;
  83.  
  84. end.
  85.